//缓存key 需要存储的缓存值value  过期时间，默认0表示永久有效expire
const setCache = (key, value, expire = 0) =>  {
    let obj = {
      data: value, //存储的数据
      time: Date.now() / 1000, //记录存储的时间戳
      expire: expire //记录过期时间，单位秒
    }
    uni.setStorageSync(key, JSON.stringify(obj))
  }
  
const getCache = (key) => {
    let val = uni.getStorageSync(key)
    if (!val) {
      return null
    }
    val = JSON.parse(val)
    if (val.expire && Date.now() / 1000 - val.time > val.expire) {
      uni.removeStorageSync(key)
      return null
    }
	
    return val.data
}

const youth_token_time = 432000

export default {
    setCache,  //时间戳转日期
	getCache,
	youth_token_time
}